package com.hucheng.rest.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hucheng.common.exception.EduException;
import com.hucheng.common.response.ServiceCoreVO;
import com.hucheng.common.utils.ValidatorUtils;
import com.hucheng.rest.base.BaseAction;
import com.hucheng.user.service.UserPointService;
import com.hucheng.user.vo.UserPointVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-11
 * @Description: 类描述
 **/
@Slf4j
@Controller("userPointAction")
public class UserPointAction extends BaseAction {

    @Reference
    private UserPointService userPointService;

    public ServiceCoreVO addUserPointV100() throws EduException {

        String point = getRequestContentValue("point");
        String source = getRequestContentValue("source");

        if (!ValidatorUtils.isInteger(point)) {
            throw new EduException(150001);
        }

        if (ValidatorUtils.isEmpty(source)) {
            throw new EduException(150002);
        }

        userPointService.addPoint(Integer.parseInt(point), source, userId);

        return response();
    }

    public ServiceCoreVO userPointV100() throws EduException {
        UserPointVO userPointVO = userPointService.getUserPoint(userId);
        return response(userPointVO);
    }

    public ServiceCoreVO cleanUserPointExpiredV100() throws EduException {
        userPointService.cleanUserPointExpired();
        return response();
    }
}
